{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "gfootball_example_from_prebuild.ipynb",
      "provenance": [],
      "collapsed_sections": [],
      "toc_visible": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/google-research/football/blob/master/gfootball/colabs/gfootball_example_from_prebuild.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "iCWQ9yUT3W61",
        "colab_type": "text"
      },
      "source": [
        "# Setup (should take < 100 seconds)"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "kB9McZ4THuor",
        "colab_type": "code",
        "colab": {}
      },
      "source": [
        "!apt-get update\n",
        "!apt-get install libsdl2-gfx-dev libsdl2-ttf-dev\n",
        "\n",
        "# Make sure that the Branch in git clone and in wget call matches !!\n",
        "!git clone -b v2.0.4 https://github.com/google-research/football.git\n",
        "!mkdir -p football/third_party/gfootball_engine/lib\n",
        "\n",
        "!wget https://storage.googleapis.com/gfootball/prebuilt_gameplayfootball_v2.0.4.so -O football/third_party/gfootball_engine/lib/prebuilt_gameplayfootball.so\n",
        "!cd football && GFOOTBALL_USE_PREBUILT_SO=1 pip3 install ."
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "GGCu8kbl21Rx",
        "colab_type": "text"
      },
      "source": [
        "# Now, you can run it:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vLg01fIo2lpV",
        "colab_type": "code",
        "outputId": "13dcac37-3f59-4f1e-f430-fed46f965ff5",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 68
        }
      },
      "source": [
        "import gfootball.env as football_env\n",
        "env = football_env.create_environment(env_name=\"academy_empty_goal_close\", stacked=False, logdir='/tmp/football', write_goal_dumps=False, write_full_episode_dumps=False, render=False)\n",
        "env.reset()\n",
        "steps = 0\n",
        "while True:\n",
        "  obs, rew, done, info = env.step(env.action_space.sample())\n",
        "  steps += 1\n",
        "  if steps % 100 == 0:\n",
        "    print(\"Step %d Reward: %f\" % (steps, rew))\n",
        "  if done:\n",
        "    break\n",
        "\n",
        "print(\"Steps: %d Reward: %.2f\" % (steps, rew))"
      ],
      "execution_count": 16,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Step 100 Reward: 0.000000\n",
            "Step 200 Reward: 0.000000\n",
            "Steps: 202 Reward: 0.00\n"
          ],
          "name": "stdout"
        }
      ]
    }
  ]
}
